<html>
<head><meta charset="utf-8"><title>Adding support for missing intrinsics? · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html">Adding support for missing intrinsics?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246115137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246115137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Egger <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246115137">(Jul 15 2021 at 15:57)</a>:</h4>
<p>Hi all, I was recently looking into improving some LLVM IR lowering for ARM DSP extensions and noticed that rustc doesn't support some of them, e.g. <a href="https://llvm.org/docs/LangRef.html#llvm-sshl-sat-intrinsics">https://llvm.org/docs/LangRef.html#llvm-sshl-sat-intrinsics</a> . Is there interest to adding and supporting them? (Of course risking a peek into the potential rabbit hole of actually having to add support for saturated shifts to libcore as well).</p>



<a name="246116839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246116839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246116839">(Jul 15 2021 at 16:08)</a>:</h4>
<p>Having more intrinsics is not exactly a goal for Rust. There must be a motivating API that can utilize them (as an implementation detail)</p>



<a name="246116919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246116919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246116919">(Jul 15 2021 at 16:09)</a>:</h4>
<p>so yeah, the order of things is to propose adding a saturated shifting APIs to libstd/core and then implementing them in terms of intrinsics or however else, as necessary, to obtain required codegen quality.</p>



<a name="246118496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246118496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Egger <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246118496">(Jul 15 2021 at 16:19)</a>:</h4>
<p>Is the team also here Zulip or where would I propose such new API functions?</p>



<a name="246119875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246119875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246119875">(Jul 15 2021 at 16:29)</a>:</h4>
<p><a class="stream" data-stream-id="219381" href="/#narrow/stream/219381-t-libs">#t-libs</a> is a good entry point for that question.</p>



<a name="246238107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246238107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246238107">(Jul 16 2021 at 15:26)</a>:</h4>
<p>Ah, I want to add, if you must use the intrinsic no matter what you can use the LLVM intrinsic through link_name tricks.</p>



<a name="246238206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246238206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246238206">(Jul 16 2021 at 15:27)</a>:</h4>
<p>e.g.</p>
<div class="codehilite"><pre><span></span><code>extern &quot;C&quot; {
    #[link_name = &quot;@llvm.sshl.sat.i32&quot;]
    fn my_shift(arg: u32, arg2: u32) -&gt; u32;
}
</code></pre></div>
<p>or something.</p>



<a name="246238273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246238273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246238273">(Jul 16 2021 at 15:28)</a>:</h4>
<p>still about as unstable as using rust-intrinsics…</p>



<a name="246250537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246250537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246250537">(Jul 16 2021 at 17:02)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">extern</span><span class="w"> </span><span class="s">"C"</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[link_name = </span><span class="s">"llvm.sshl.sat.i32"</span><span class="cp">]</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">my_shift</span><span class="p">(</span><span class="n">arg</span>: <span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">arg2</span>: <span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u32</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>gives</p>
<div class="codehilite"><pre><span></span><code>error[E0658]: linking to LLVM intrinsics is experimental
 --&gt; src/lib.rs:3:5
  |
3 |     fn my_shift(arg: u32, arg2: u32) -&gt; u32;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #29602 &lt;https://github.com/rust-lang/rust/issues/29602&gt; for more information
  = help: add `#![feature(link_llvm_intrinsics)]` to the crate attributes to enable
</code></pre></div>



<a name="246252494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246252494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246252494">(Jul 16 2021 at 17:18)</a>:</h4>
<p><span class="user-mention" data-user-id="263083">@Daniel Egger</span> We're happy to accept more ARM intrinsics in stdarch. The saturating shift intrinsics are specified in the ACLE (ARM C language extension).</p>



<a name="246263889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246263889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246263889">(Jul 16 2021 at 18:51)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> yes, using regular intrinsics is similarly unstable.</p>



<a name="246270753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20support%20for%20missing%20intrinsics%3F/near/246270753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Egger <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F.html#246270753">(Jul 16 2021 at 19:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Adding.20support.20for.20missing.20intrinsics.3F/near/246252494">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="263083">Daniel Egger</span> We're happy to accept more ARM intrinsics in stdarch. The saturating shift intrinsics are specified in the ACLE (ARM C language extension).</p>
</blockquote>
<p>Thanks. I'll have a look whether something is missing and will PR it. Ultimately my goal would be the ability to write regular Rust code which compiles on any architecture to optimal code, though.  We're not doing too shabby in that regard, Rust very nicely generates suitable IR for e.g. saturating functions which are lowered into ARM DSP instructions. LLVM needs some work though to support more than just a single value out of 2 or 4.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>